<?php
/**
 * Created by PhpStorm.
 * User: jwb
 * Date: 2020/9/8
 * Time: 15:35
 */

namespace App\Admin\Extensions\Actions;


use Encore\Admin\Actions\RowAction;

class ModalRowAction extends  RowAction
{
    public $a_name;
    /**
     *
     */
    public function form()
    {

    }
    /**
     * @param \Encore\Admin\Grid\Displayers\Actions $actions
     * @param null $name
     */
    public function setActions(\Encore\Admin\Grid\Displayers\Actions $actions, $name=null)
    {
        $this->setGrid($actions->getGrid())->setRow($actions->row);
        $this->setName($name);
        return $this;
    }
    /**
     * @param $name
     */
    public function setName($name)
    {
        if(!$this->name){
            $this->setTitle($name);
        }
        $this->a_name = $name?:$this->a_name;
        return $this;
    }

    public function setTitle($title)
    {
        $this->name = $title?:$this->name;
    }

    public function getAName()
    {
        return $this->a_name;
    }

    /**
     * Render row action.
     *
     * @return string
     */
    public function render()
    {
        if ($href = $this->href()) {
            return "<a href='{$href}'>{$this->name()}</a>";
        }

        $this->addScript();

        $attributes = $this->formatAttributes();

        return sprintf(
            "<a data-_key='%s' href='javascript:void(0);' class='%s' {$attributes}>%s</a>",
            $this->getKey(),
            $this->getElementClass(),
            $this->getAName()
        );
    }
}